const BillDao=require("../../dao/bill/bill_dao.js");

const BillService={
	//添加订单
	add(req,res,next){
		// 获取 POST 请求中传递的数据
		const {name,company,count,money} = req.body;
		console.log("说明",req.body);
		//保存到数据库
		BillDao.save({name,company,count,money})
					.then((data)=>{
						res.json({
							res_code:1,
							res_error:"",
							res_body:{
								status:1,
								data:data
							}	
						});
					})
					.then((err)=>{
						res.json({
							res_code:0,
							res_error:err,
							res_body:{}
						});
					});
	},
	// 分页查询
	findByPage(req, res, next) {
		// 获取查询的页码
		const {page} = req.query;
		// 查询指定页码的数据
		BillDao.findByPage(page)
				.then((data) => {
					res.json({
						res_code: 1,
						res_error: "",
						res_body: {
							status: 1,
							list: data
						}
					});
				})
				.catch((err) => {
					res.json({
						res_code: 0,
						res_error: err,
						res_body: {}
					});
				});
	},
	//删除订单
	delete(req,res,next){
		const {id}=req.body;
		console.log("12345",req.body);
		console.log(id);
		BillDao.delete(id)
			.then((data) => {
					res.json({
						res_code: 1,
						res_error: "",
						res_body: {
							status: 1,
							list: data
						}
					});
				})
				.catch((err) => {
					res.json({
						res_code: 0,
						res_error: err,
						res_body: {}
					});
				});
		}
	}



module.exports=BillService;